package cn.yangliu.source;

import cn.yangliu.bean.ProjectSetting;
import cn.yangliu.bean.ServiceSetting;

import java.io.File;

public class ServiceImplSource extends CodeSource {

    private Boolean createInterface;

    private Boolean useBaseService;

    private Boolean useTransactional;

    private ServiceSource serviceSource;

    private MapperSource mapperSource;

    private EntitySource entitySource;

    public ServiceImplSource(ProjectSetting projectSetting, ServiceSetting serviceSetting, MapperSource mapperSource) {
        super(projectSetting, serviceSetting.getServicePackage(), projectSetting.getCodePath());

        this.mapperSource = mapperSource;
        this.useTransactional = serviceSetting.getUseTransactional();
        this.entitySource = mapperSource.getEntitySource();
        if (serviceSetting.getCreateInterface()) {
            serviceSource = new ServiceSource(projectSetting, serviceSetting, entitySource);
        }
        init(serviceSetting, entitySource.shortName, projectSetting.getCodePath());
    }

    private void init(ServiceSetting serviceSetting, String entityName, String srcPath) {
        createInterface = serviceSetting.getCreateInterface();
        useBaseService = serviceSetting.getUseBaseService();
        if (serviceSetting.getCreateInterface()) {
            shortName = entityName + "ServiceImpl";
            fullPackage += ".impl";
            filename = shortName + ".java";
            filepath += File.separator +"impl";
        } else {
            shortName = entityName + "Service";
            filename = shortName + ".java";
        }

        classFullName = fullPackage + "." + shortName;

        filepath = filepath.replace(".", File.separator);

    }

    public Boolean getCreateInterface() {
        return createInterface;
    }

    public void setCreateInterface(Boolean createInterface) {
        this.createInterface = createInterface;
    }

    public Boolean getUseBaseService() {
        return useBaseService;
    }

    public void setUseBaseService(Boolean useBaseService) {
        this.useBaseService = useBaseService;
    }

    public Boolean getUseTransactional() {
        return useTransactional;
    }

    public void setUseTransactional(Boolean useTransactional) {
        this.useTransactional = useTransactional;
    }

    public ServiceSource getServiceSource() {
        return serviceSource;
    }

    public void setServiceSource(ServiceSource serviceSource) {
        this.serviceSource = serviceSource;
    }

    public MapperSource getMapperSource() {
        return mapperSource;
    }

    public void setMapperSource(MapperSource mapperSource) {
        this.mapperSource = mapperSource;
    }

    public EntitySource getEntitySource() {
        return entitySource;
    }

    public void setEntitySource(EntitySource entitySource) {
        this.entitySource = entitySource;
    }
}
